Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var WPInv_Admin; |
||
2 | jQuery(document).ready(function($) { |
||
3 | var WPInv_Recurring = { |
||
4 | init: function() { |
||
5 | //Recurring select field conditionals |
||
6 | this.edit_product_id(); |
||
7 | this.edit_profile_id(); |
||
8 | this.edit_txn_id(); |
||
9 | this.delete(); |
||
10 | }, |
||
11 | /** |
||
12 | * Edit Subscription Text Input |
||
13 | */ |
||
14 | edit_subscription_input: function(link, input) { |
||
15 | //User clicks edit |
||
16 | if (link.text() === WPInv_Admin.action_edit) { |
||
|
|||
17 | //Preserve current value |
||
18 | link.data('current-value', input.val()); |
||
19 | //Update text to 'cancel' |
||
20 | link.text(WPInv_Admin.action_cancel); |
||
21 | } else { |
||
22 | //User clicked cancel, return previous value |
||
23 | input.val(link.data('current-value')); |
||
24 | //Update link text back to 'edit' |
||
25 | link.text(WPInv_Admin.action_edit); |
||
26 | } |
||
27 | }, |
||
28 | edit_profile_id: function() { |
||
29 | $('.wpinv-edit-sub-profile-id').on('click', function(e) { |
||
30 | e.preventDefault(); |
||
31 | var link = $(this); |
||
32 | var profile_input = $('input.wpinv-sub-profile-id'); |
||
33 | WPInv_Recurring.edit_subscription_input(link, profile_input); |
||
34 | $('.wpinv-sub-profile-id').toggle(); |
||
35 | $('#wpinv-sub-profile-id-update-notice').slideToggle(); |
||
36 | }); |
||
37 | }, |
||
38 | edit_product_id: function() { |
||
39 | $('.wpinv-sub-product-id').on('change', function(e) { |
||
40 | e.preventDefault(); |
||
41 | $('#wpinv-sub-product-update-notice').slideDown(); |
||
42 | }); |
||
43 | }, |
||
44 | edit_txn_id: function() { |
||
45 | $('.wpinv-edit-sub-transaction-id').on('click', function(e) { |
||
46 | e.preventDefault(); |
||
47 | var link = $(this); |
||
48 | var txn_input = $('input.wpinv-sub-transaction-id'); |
||
49 | WPInv_Recurring.edit_subscription_input(link, txn_input); |
||
50 | $('.wpinv-sub-transaction-id').toggle(); |
||
51 | }); |
||
52 | }, |
||
53 | delete: function() { |
||
54 | $('.wpinv-delete-subscription').on('click', function(e) { |
||
55 | if (confirm(WPInv_Admin.delete_subscription)) { |
||
56 | return true; |
||
57 | } |
||
58 | return false; |
||
59 | }); |
||
60 | } |
||
61 | }; |
||
62 | WPInv_Recurring.init(); |
||
63 | }); |